package com.atguigu.tingshu.user.api;

import com.atguigu.tingshu.common.login.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.util.AuthContextHolder;
import com.atguigu.tingshu.user.service.UserListenProcessService;
import com.atguigu.tingshu.vo.user.UserListenProcessVo;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;

@Tag(name = "用户声音播放进度管理接口")
@RestController
@RequestMapping("api/user")
@SuppressWarnings({"all"})
public class UserListenProcessApiController {

    @Autowired
    private UserListenProcessService userListenProcessService;


    /**
     * 获取当前用户声音播放进度
     *
     * @param trackId 声音ID
     * @return
     */
    @GuiGuLogin(required = false)  //true:必须登录  false:不登录
    @GetMapping("/userListenProcess/getTrackBreakSecond/{trackId}")
    public Result<BigDecimal> getTrackBreakSecond(@PathVariable Long trackId) {
        Long userId = AuthContextHolder.getUserId();
        BigDecimal breakSecond = userListenProcessService.getTrackBreakSecond(userId, trackId);
        return Result.ok(breakSecond);
    }

    /**
     * 更新声音播放进度及播放统计信息
     *
     * @param userListenProcessVo
     * @return
     */
    @GuiGuLogin(required = false)
    @PostMapping("/userListenProcess/updateListenProcess")
    public Result updateListenProcess(@RequestBody UserListenProcessVo userListenProcessVo) {
        Long userId = AuthContextHolder.getUserId();
        userListenProcessService.updateListenProcess(userId, userListenProcessVo);
        return Result.ok();
    }

    /**
     * 获取当前登录用户上次播放声音记录，用于快速播放
     *
     * @return
     */
    @GuiGuLogin(required = false)
    @GetMapping("/userListenProcess/getLatelyTrack")
    public Result<Map<String, Long>> getLatelyTrack() {
        Map<String, Long> mapResult = userListenProcessService.getLatelyTrack();
        return Result.ok(mapResult);

    }

}

